package co.edu.unal.geditor.view.tools;

import java.awt.Color;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import co.edu.unal.geditor.controller.action.tool.TextToolAction;
import co.edu.unal.geditor.model.GraphElement;
import co.edu.unal.geditor.model.RectangleElement;
import co.edu.unal.geditor.model.TextElement;

public class TextCreationTool extends CreationTool implements ActionListener
{
	// v0.6 : TextCreationTool provides its own Factory class 
	private static class Factory extends ToolFactory
	{
		protected Tool create()
		{
			return new TextCreationTool();
		}
	}

	// this block executed when the class object is loaded in the VM
	// registers its Factory 
	static
	{
		ToolFactory.register( TextCreationTool.class.getName(), new Factory() );
	}
	
	@Override
	public GraphElement createObject( Point ptPressed, Point ptReleased )
	{
		String text=null;
		
		do{
			text = JOptionPane.showInputDialog("Text Tool");
		}while(text==null);
		
		
			//TODO:Text tool JJ size
			//TODO:Arreglar la opcion de cancel
			
		
		
		
		TextElement txt = new TextElement( ptPressed, ptReleased,text );
		//txt.setSelected( true );

		return txt;
	}

	@Override
	protected void initAction()
	{
		setAction( new TextToolAction() );
		if(feedbackGraphElemet==null)
		{
		feedbackGraphElemet = new RectangleElement(new Point(0,0), new Point(20,20),Color.white);
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		//do nothing
	}
}